unit MetodosFormasPagamento;

interface

uses Dmcaixa, SysUtils;

type
  TMetodosFormasPagamento  = class

  protected
    constructor Create;
    destructor  Destroy;
  public
    function  vlTotalPagamento(nroCupom : String): Double;
    function  deletarForma(nroCupom : string) : boolean;
    procedure ExcluirFormadoDocumento(nroCupom : String; codFormaPag : integer) ;


end;

implementation

{construtor da classe}
constructor TMetodosFormasPagamento.Create;
begin
  inherited Create;
end;

{destrutor da classe}
destructor TMetodosFormasPagamento.Destroy;
begin
  inherited Destroy;
end;


function TMetodosFormasPagamento.vlTotalPagamento(nroCupom : String): Double;
var vlTotal : Double;
begin
  inherited;
  PreparaQuery('select sum(CAIXAFORMA.VALOR) as total from CAIXAFORMA where DOCUMENTO = ' + QuotedStr(nroCupom)+
               ' and cliche=' + QuotedStr(InttoStr(NroCaixa)) +
               ' and codloja=' + QuotedStr(InttoStr(CodLoja)) + ';' ,dmcaixas.sqlq_geral);
  ExecutaQuery(dmcaixas.sqlq_geral);
  with dmcaixas.sqlq_geral
  do begin
     vlTotal := FieldByName('total').AsFloat;
  end;
  Result := vlTotal;
end;

function TMetodosFormasPagamento.deletarForma(nroCupom : string) : boolean;
begin
  try
    PreparaQuery('delete from CAIXAFORMA where DOCUMENTO = '  + QuotedStr(nroCupom)+
               ' and cliche=' + QuotedStr(InttoStr(NroCaixa)) +
               ' and codloja=' + QuotedStr(InttoStr(CodLoja)) + ';' ,dmcaixas.sqlq_geral);
    ExecutaQuery(dmcaixas.sqlq_geral);
  finally
    Result := true;
  end;
end;
{**************  exclui forma de pagamento de um cupom ************************}
procedure TMetodosFormasPagamento.ExcluirFormadoDocumento(nroCupom : String; codFormaPag : integer) ;
begin
  PreparaQuery('delete from CAIXAFORMA where DOCUMENTO = '    + QuotedStr(nroCupom) +
               ' and cliche='  + QuotedStr(InttoStr(NroCaixa))+
               ' and codloja=' + QuotedStr(InttoStr(CodLoja)) +
               ' and CODFORMAPAG =' + QuotedStr( IntToStr(codFormaPag ) ) + ';' ,dmcaixas.sqlq_geral);
  DMCaixas.sqlq_geral.ExecSQL;
end;


end.
